{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1002\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1002\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1002\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "from bokeh.models import ColumnDataSource\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 堆叠柱状图（纵向）\n",
    "## DEMO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.palettes import Spectral3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备 \n",
    "data = {'fruits' : ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'],\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 4, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3],\n",
    "#         'years' : [\"2015\", \"2016\", \"2017\"]\n",
    "}\n",
    "# 颜色的准备\n",
    "colors=Spectral3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3f6ddf59-0d0c-4245-8ca8-c8eae70efebe\" data-root-id=\"1271\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"03a27c87-a34a-4bb9-af62-328b757f52b6\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1282\"}],\"center\":[{\"id\":\"1284\"},{\"id\":\"1288\"},{\"id\":\"1324\"}],\"left\":[{\"id\":\"1285\"}],\"outline_line_color\":null,\"plot_height\":300,\"renderers\":[{\"id\":\"1314\"},{\"id\":\"1329\"},{\"id\":\"1343\"}],\"title\":{\"id\":\"1272\"},\"toolbar\":{\"id\":\"1297\"},\"x_range\":{\"id\":\"1274\"},\"x_scale\":{\"id\":\"1278\"},\"y_range\":{\"id\":\"1276\"},\"y_scale\":{\"id\":\"1280\"}},\"id\":\"1271\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"],\"range_padding\":0.1},\"id\":\"1274\",\"type\":\"FactorRange\"},{\"attributes\":{\"fields\":[\"2015\"]},\"id\":\"1306\",\"type\":\"Stack\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1295\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1305\"}},\"fill_color\":{\"value\":\"#99d594\"},\"line_color\":{\"value\":\"#99d594\"},\"top\":{\"expr\":{\"id\":\"1306\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1312\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1293\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1290\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1280\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1292\",\"type\":\"SaveTool\"},{\"attributes\":{\"label\":{\"value\":\"2015\"},\"renderers\":[{\"id\":\"1314\"}]},\"id\":\"1325\",\"type\":\"LegendItem\"},{\"attributes\":{\"data_source\":{\"id\":\"1270\"},\"glyph\":{\"id\":\"1312\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2015\",\"nonselection_glyph\":{\"id\":\"1313\"},\"selection_glyph\":null,\"view\":{\"id\":\"1315\"}},\"id\":\"1314\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1282\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1284\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"2015\":[2,1,4,3,2,4],\"2016\":[5,3,4,2,4,6],\"2017\":[3,2,4,4,5,3],\"fruits\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1321\"},\"selection_policy\":{\"id\":\"1322\"}},\"id\":\"1270\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1294\",\"type\":\"HelpTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1270\"},\"glyph\":{\"id\":\"1341\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2017\",\"nonselection_glyph\":{\"id\":\"1342\"},\"selection_glyph\":null,\"view\":{\"id\":\"1344\"}},\"id\":\"1343\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1286\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1270\"}},\"id\":\"1315\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1305\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#99d594\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#99d594\"},\"top\":{\"expr\":{\"id\":\"1306\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1313\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[]},\"id\":\"1305\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"1322\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1289\",\"type\":\"PanTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1289\"},{\"id\":\"1290\"},{\"id\":\"1291\"},{\"id\":\"1292\"},{\"id\":\"1293\"},{\"id\":\"1294\"},{\"id\":\"1296\"}]},\"id\":\"1297\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"1270\"}},\"id\":\"1330\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1309\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fc8d59\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fc8d59\"},\"top\":{\"expr\":{\"id\":\"1310\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1342\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"value\":\"2017\"},\"renderers\":[{\"id\":\"1343\"}]},\"id\":\"1353\",\"type\":\"LegendItem\"},{\"attributes\":{\"items\":[{\"id\":\"1325\"},{\"id\":\"1339\"},{\"id\":\"1353\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"1324\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1283\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1317\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"1272\",\"type\":\"Title\"},{\"attributes\":{\"end\":16,\"start\":0},\"id\":\"1276\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1321\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1319\"},\"minor_tick_line_color\":null,\"ticker\":{\"id\":\"1286\"}},\"id\":\"1285\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1278\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"$name\",\"@fruits: @$name\"]]},\"id\":\"1296\",\"type\":\"HoverTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1307\"}},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"1308\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1327\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1319\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1309\"}},\"fill_color\":{\"value\":\"#fc8d59\"},\"line_color\":{\"value\":\"#fc8d59\"},\"top\":{\"expr\":{\"id\":\"1310\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1341\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\"]},\"id\":\"1309\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"1307\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"1308\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"fruits\"}},\"id\":\"1328\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1317\"},\"minor_tick_line_color\":null,\"ticker\":{\"id\":\"1283\"}},\"id\":\"1282\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"overlay\":{\"id\":\"1295\"}},\"id\":\"1291\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\"]},\"id\":\"1308\",\"type\":\"Stack\"},{\"attributes\":{\"data_source\":{\"id\":\"1270\"},\"glyph\":{\"id\":\"1327\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2016\",\"nonselection_glyph\":{\"id\":\"1328\"},\"selection_glyph\":null,\"view\":{\"id\":\"1330\"}},\"id\":\"1329\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1285\"},\"dimension\":1,\"ticker\":null},\"id\":\"1288\",\"type\":\"Grid\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\",\"2017\"]},\"id\":\"1310\",\"type\":\"Stack\"},{\"attributes\":{\"source\":{\"id\":\"1270\"}},\"id\":\"1344\",\"type\":\"CDSView\"},{\"attributes\":{\"fields\":[\"2015\"]},\"id\":\"1307\",\"type\":\"Stack\"},{\"attributes\":{\"label\":{\"value\":\"2016\"},\"renderers\":[{\"id\":\"1329\"}]},\"id\":\"1339\",\"type\":\"LegendItem\"}],\"root_ids\":[\"1271\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"03a27c87-a34a-4bb9-af62-328b757f52b6\",\"root_ids\":[\"1271\"],\"roots\":{\"1271\":\"3f6ddf59-0d0c-4245-8ca8-c8eae70efebe\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1271"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data=data\n",
    ")\n",
    "# 点击的交互式数据\n",
    "TOOLTIPS = [\n",
    "    # ('标题','数据')\n",
    "    (\"$name\", \"@fruits: @$name\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=fruits,\n",
    "    plot_height=300,\n",
    "    title=\"Fruit Counts by Year\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘图(vbar_stack),直接堆叠各年数据\n",
    "p.vbar_stack(years,\n",
    "             x='fruits ',\n",
    "             width=0.9,\n",
    "             color=colors,\n",
    "             source=source,\n",
    "             legend=[value(x) for x in years]\n",
    ") # legend=[{'value': '2015'}, {'value': '2016'}, {'value': '2017'}]\n",
    "    \n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.y_range.end = 16\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.axis.minor_tick_line_color = None\n",
    "p.outline_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>指标</th>\n",
       "      <th>2022年第一季度</th>\n",
       "      <th>2021年第四季度</th>\n",
       "      <th>2021年第三季度</th>\n",
       "      <th>2021年第二季度</th>\n",
       "      <th>2021年第一季度</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>13360</td>\n",
       "      <td>44993</td>\n",
       "      <td>35694</td>\n",
       "      <td>23604</td>\n",
       "      <td>12636</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>16230</td>\n",
       "      <td>54854</td>\n",
       "      <td>43592</td>\n",
       "      <td>28897</td>\n",
       "      <td>15472</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>6639</td>\n",
       "      <td>22306</td>\n",
       "      <td>17619</td>\n",
       "      <td>11490</td>\n",
       "      <td>6225</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>20630</td>\n",
       "      <td>75002</td>\n",
       "      <td>56498</td>\n",
       "      <td>38138</td>\n",
       "      <td>19585</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>22274</td>\n",
       "      <td>81518</td>\n",
       "      <td>61243</td>\n",
       "      <td>41381</td>\n",
       "      <td>21189</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>10016</td>\n",
       "      <td>33303</td>\n",
       "      <td>26125</td>\n",
       "      <td>17383</td>\n",
       "      <td>9326</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>22663</td>\n",
       "      <td>78027</td>\n",
       "      <td>58907</td>\n",
       "      <td>40357</td>\n",
       "      <td>21548</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>23772</td>\n",
       "      <td>82429</td>\n",
       "      <td>61915</td>\n",
       "      <td>42348</td>\n",
       "      <td>22636</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>12891</td>\n",
       "      <td>38521</td>\n",
       "      <td>31985</td>\n",
       "      <td>22535</td>\n",
       "      <td>12006</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>19366</td>\n",
       "      <td>57541</td>\n",
       "      <td>44712</td>\n",
       "      <td>30998</td>\n",
       "      <td>18263</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>22784</td>\n",
       "      <td>68487</td>\n",
       "      <td>52758</td>\n",
       "      <td>36294</td>\n",
       "      <td>21600</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>12541</td>\n",
       "      <td>35247</td>\n",
       "      <td>28474</td>\n",
       "      <td>20357</td>\n",
       "      <td>11686</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>16490</td>\n",
       "      <td>47498</td>\n",
       "      <td>36227</td>\n",
       "      <td>25119</td>\n",
       "      <td>15500</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>城镇居民人均可支配收入累计值(元)</td>\n",
       "      <td>19251</td>\n",
       "      <td>57743</td>\n",
       "      <td>44267</td>\n",
       "      <td>30491</td>\n",
       "      <td>18194</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>农村居民人均可支配收入累计值(元)</td>\n",
       "      <td>10952</td>\n",
       "      <td>26791</td>\n",
       "      <td>20267</td>\n",
       "      <td>14455</td>\n",
       "      <td>10215</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   指标  2022年第一季度  2021年第四季度  2021年第三季度  2021年第二季度  2021年第一季度  \\\n",
       "0     居民人均可支配收入累计值(元)      13360      44993      35694      23604      12636   \n",
       "1   城镇居民人均可支配收入累计值(元)      16230      54854      43592      28897      15472   \n",
       "2   农村居民人均可支配收入累计值(元)       6639      22306      17619      11490       6225   \n",
       "3     居民人均可支配收入累计值(元)      20630      75002      56498      38138      19585   \n",
       "4   城镇居民人均可支配收入累计值(元)      22274      81518      61243      41381      21189   \n",
       "5   农村居民人均可支配收入累计值(元)      10016      33303      26125      17383       9326   \n",
       "6     居民人均可支配收入累计值(元)      22663      78027      58907      40357      21548   \n",
       "7   城镇居民人均可支配收入累计值(元)      23772      82429      61915      42348      22636   \n",
       "8   农村居民人均可支配收入累计值(元)      12891      38521      31985      22535      12006   \n",
       "9     居民人均可支配收入累计值(元)      19366      57541      44712      30998      18263   \n",
       "10  城镇居民人均可支配收入累计值(元)      22784      68487      52758      36294      21600   \n",
       "11  农村居民人均可支配收入累计值(元)      12541      35247      28474      20357      11686   \n",
       "12    居民人均可支配收入累计值(元)      16490      47498      36227      25119      15500   \n",
       "13  城镇居民人均可支配收入累计值(元)      19251      57743      44267      30491      18194   \n",
       "14  农村居民人均可支配收入累计值(元)      10952      26791      20267      14455      10215   \n",
       "\n",
       "     地区  \n",
       "0   广东省  \n",
       "1   广东省  \n",
       "2   广东省  \n",
       "3    北京  \n",
       "4    北京  \n",
       "5    北京  \n",
       "6   上海市  \n",
       "7   上海市  \n",
       "8   上海市  \n",
       "9   浙江省  \n",
       "10  浙江省  \n",
       "11  浙江省  \n",
       "12  江苏省  \n",
       "13  江苏省  \n",
       "14  江苏省  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 学生实践\n",
    "## 数据准备\n",
    "import pandas as pd\n",
    "pd.read_csv('居民人均可支配收入.csv')\n",
    "df = pd.read_csv('居民人均可支配收入.csv')\n",
    "df\n",
    "# pd.read_csv('居民人均可支配收入.txt',sep=\"，\",encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>指标</th>\n",
       "      <th>2022年第一季度</th>\n",
       "      <th>2021年第四季度</th>\n",
       "      <th>2021年第三季度</th>\n",
       "      <th>2021年第二季度</th>\n",
       "      <th>2021年第一季度</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>13360</td>\n",
       "      <td>44993</td>\n",
       "      <td>35694</td>\n",
       "      <td>23604</td>\n",
       "      <td>12636</td>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>20630</td>\n",
       "      <td>75002</td>\n",
       "      <td>56498</td>\n",
       "      <td>38138</td>\n",
       "      <td>19585</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>22663</td>\n",
       "      <td>78027</td>\n",
       "      <td>58907</td>\n",
       "      <td>40357</td>\n",
       "      <td>21548</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>19366</td>\n",
       "      <td>57541</td>\n",
       "      <td>44712</td>\n",
       "      <td>30998</td>\n",
       "      <td>18263</td>\n",
       "      <td>浙江省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>居民人均可支配收入累计值(元)</td>\n",
       "      <td>16490</td>\n",
       "      <td>47498</td>\n",
       "      <td>36227</td>\n",
       "      <td>25119</td>\n",
       "      <td>15500</td>\n",
       "      <td>江苏省</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 指标  2022年第一季度  2021年第四季度  2021年第三季度  2021年第二季度  2021年第一季度  \\\n",
       "0   居民人均可支配收入累计值(元)      13360      44993      35694      23604      12636   \n",
       "3   居民人均可支配收入累计值(元)      20630      75002      56498      38138      19585   \n",
       "6   居民人均可支配收入累计值(元)      22663      78027      58907      40357      21548   \n",
       "9   居民人均可支配收入累计值(元)      19366      57541      44712      30998      18263   \n",
       "12  居民人均可支配收入累计值(元)      16490      47498      36227      25119      15500   \n",
       "\n",
       "     地区  \n",
       "0   广东省  \n",
       "3    北京  \n",
       "6   上海市  \n",
       "9   浙江省  \n",
       "12  江苏省  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_居民人均可支配收入累计值 = df.query('指标==\"居民人均可支配收入累计值(元)\"')\n",
    "df_居民人均可支配收入累计值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['指标', '2022年第一季度', '2021年第四季度', '2021年第三季度', '2021年第二季度', '2021年第一季度', '地区']"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_居民人均可支配收入累计值.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "region=df_居民人均可支配收入累计值['地区'].to_list()\n",
    "R1=居民人均可支配收入累计值['2022年第一季度'].to_list()\n",
    "R2=居民人均可支配收入累计值['2021年第四季度'].to_list()\n",
    "R3=居民人均可支配收入累计值['2021年第三季度'].to_list()\n",
    "R4=居民人均可支配收入累计值['2021年第二季度'].to_list()\n",
    "R5=居民人均可支配收入累计值['2021年第一季度'].to_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'region': ['广东省', '北京', '上海市', '浙江省', '江苏省'],\n",
       " '2022年第一季度': [13360, 20630, 22663, 19366, 16490],\n",
       " '2021年第四季度': [44993, 75002, 78027, 57541, 47498],\n",
       " '2021年第三季度': [35694, 56498, 58907, 44712, 36227],\n",
       " '2021年第二季度': [23604, 38138, 40357, 30998, 25119],\n",
       " '2021年第一季度': [12636, 19585, 21548, 18263, 15500]}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral5\n",
    "data = {'region' : region,\n",
    "        '2022年第一季度': R1,\n",
    "        '2021年第四季度': R2,\n",
    "        '2021年第三季度': R3,\n",
    "        '2021年第二季度': R4,\n",
    "        '2021年第一季度': R5,\n",
    "       }\n",
    "colors= Spectral5\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "jidu=[\"2022年第一季度\", \"2021年第四季度\", \"2021年第三季度\",\"2021年第二季度\",\"2021年第一季度\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"22127a7b-7e6a-42e8-a16d-50a43d1b9633\" data-root-id=\"8141\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"2a74f81d-066b-4a43-bc7c-69ae755f7948\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"8152\"}],\"center\":[{\"id\":\"8154\"},{\"id\":\"8158\"},{\"id\":\"8198\"}],\"left\":[{\"id\":\"8155\"}],\"plot_height\":500,\"plot_width\":900,\"renderers\":[{\"id\":\"8188\"},{\"id\":\"8203\"},{\"id\":\"8217\"},{\"id\":\"8231\"},{\"id\":\"8245\"}],\"title\":{\"id\":\"8142\"},\"toolbar\":{\"id\":\"8167\"},\"x_range\":{\"id\":\"8144\"},\"x_scale\":{\"id\":\"8148\"},\"y_range\":{\"id\":\"8146\"},\"y_scale\":{\"id\":\"8150\"}},\"id\":\"8141\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8181\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fdae61\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"8182\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8230\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"8148\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data_source\":{\"id\":\"8140\"},\"glyph\":{\"id\":\"8229\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"8230\"},\"selection_glyph\":null,\"view\":{\"id\":\"8232\"}},\"id\":\"8231\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"8140\"}},\"id\":\"8232\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"8193\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"8140\"},\"glyph\":{\"id\":\"8201\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"8202\"},\"selection_glyph\":null,\"view\":{\"id\":\"8204\"}},\"id\":\"8203\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data_source\":{\"id\":\"8140\"},\"glyph\":{\"id\":\"8186\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"8187\"},\"selection_glyph\":null,\"view\":{\"id\":\"8189\"}},\"id\":\"8188\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"8193\"},\"ticker\":{\"id\":\"8156\"}},\"id\":\"8155\",\"type\":\"LinearAxis\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8181\"}},\"fill_color\":{\"value\":\"#fdae61\"},\"line_color\":{\"value\":\"#fdae61\"},\"top\":{\"expr\":{\"id\":\"8182\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8229\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"8140\"},\"glyph\":{\"id\":\"8215\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"8216\"},\"selection_glyph\":null,\"view\":{\"id\":\"8218\"}},\"id\":\"8217\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8175\"}},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"8176\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8186\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"8160\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"8177\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"8180\",\"type\":\"Stack\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"8159\"},{\"id\":\"8160\"},{\"id\":\"8161\"},{\"id\":\"8162\"},{\"id\":\"8163\"},{\"id\":\"8164\"},{\"id\":\"8166\"}]},\"id\":\"8167\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\",\"@region:@$name\"]]},\"id\":\"8166\",\"type\":\"HoverTool\"},{\"attributes\":{\"label\":{\"value\":\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"8231\"}]},\"id\":\"8241\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8159\",\"type\":\"PanTool\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"8176\",\"type\":\"Stack\"},{\"attributes\":{\"overlay\":{\"id\":\"8165\"}},\"id\":\"8161\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"8183\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"8178\",\"type\":\"Stack\"},{\"attributes\":{\"data\":{\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\":[12636,19585,21548,18263,15500],\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\":[35694,56498,58907,44712,36227],\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\":[23604,38138,40357,30998,25119],\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\":[44993,75002,78027,57541,47498],\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\":[13360,20630,22663,19366,16490],\"region\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"]},\"selected\":{\"id\":\"8195\"},\"selection_policy\":{\"id\":\"8196\"}},\"id\":\"8140\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"8191\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"8203\"}]},\"id\":\"8213\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8196\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"8140\"}},\"id\":\"8218\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"],\"range_padding\":0.1},\"id\":\"8144\",\"type\":\"FactorRange\"},{\"attributes\":{\"fields\":[]},\"id\":\"8175\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"]},\"id\":\"8179\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8179\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"8180\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8216\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"]},\"id\":\"8184\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8179\"}},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"8180\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8215\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"8191\"},\"ticker\":{\"id\":\"8153\"}},\"id\":\"8152\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"]},\"id\":\"8181\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8175\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#2b83ba\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#2b83ba\"},\"top\":{\"expr\":{\"id\":\"8176\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8187\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"8156\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8183\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#d7191c\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"8184\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8244\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"8164\",\"type\":\"HelpTool\"},{\"attributes\":{\"items\":[{\"id\":\"8199\"},{\"id\":\"8213\"},{\"id\":\"8227\"},{\"id\":\"8241\"},{\"id\":\"8255\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"8198\",\"type\":\"Legend\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8177\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#abdda4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"8178\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8202\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"]},\"id\":\"8182\",\"type\":\"Stack\"},{\"attributes\":{\"axis\":{\"id\":\"8155\"},\"dimension\":1,\"ticker\":null},\"id\":\"8158\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"8150\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"8162\",\"type\":\"SaveTool\"},{\"attributes\":{\"label\":{\"value\":\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"8188\"}]},\"id\":\"8199\",\"type\":\"LegendItem\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8183\"}},\"fill_color\":{\"value\":\"#d7191c\"},\"line_color\":{\"value\":\"#d7191c\"},\"top\":{\"expr\":{\"id\":\"8184\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8243\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"8153\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"text\":\"\\u5c45\\u6c11\\u4eba\\u5747\\u53ef\\u652f\\u914d\\u6536\\u5165\\u7d2f\\u8ba1\\u503c\\u4e94\\u5b63\\u5ea6\\u5806\\u53e0\\u67f1\\u72b6\\u56fe\"},\"id\":\"8142\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"8140\"}},\"id\":\"8246\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"8165\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"8140\"},\"glyph\":{\"id\":\"8243\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\",\"nonselection_glyph\":{\"id\":\"8244\"},\"selection_glyph\":null,\"view\":{\"id\":\"8246\"}},\"id\":\"8245\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"8177\"}},\"fill_color\":{\"value\":\"#abdda4\"},\"line_color\":{\"value\":\"#abdda4\"},\"top\":{\"expr\":{\"id\":\"8178\"}},\"width\":{\"value\":0.7},\"x\":{\"field\":\"region\"}},\"id\":\"8201\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"8140\"}},\"id\":\"8204\",\"type\":\"CDSView\"},{\"attributes\":{\"start\":0},\"id\":\"8146\",\"type\":\"DataRange1d\"},{\"attributes\":{\"label\":{\"value\":\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"8217\"}]},\"id\":\"8227\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8195\",\"type\":\"Selection\"},{\"attributes\":{\"label\":{\"value\":\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"},\"renderers\":[{\"id\":\"8245\"}]},\"id\":\"8255\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"8163\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"8152\"},\"ticker\":null},\"id\":\"8154\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"8140\"}},\"id\":\"8189\",\"type\":\"CDSView\"}],\"root_ids\":[\"8141\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"2a74f81d-066b-4a43-bc7c-69ae755f7948\",\"root_ids\":[\"8141\"],\"roots\":{\"8141\":\"22127a7b-7e6a-42e8-a16d-50a43d1b9633\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "8141"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source= ColumnDataSource(\n",
    "    data=data\n",
    ")\n",
    "\n",
    "# 点击的交互式数据\n",
    "TOOLTIPS =[\n",
    "#     ('标题','数据')\n",
    "    (\"\",'@region:@$name')\n",
    "    \n",
    "]\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=region,\n",
    "    plot_width=900,\n",
    "    plot_height=500, \n",
    "    title=\"居民人均可支配收入累计值五季度堆叠柱状图\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "p.vbar_stack(jidu, x='region', width=0.7, color=colors, source=source,\n",
    "             legend=[value(x) for x in jidu]) \n",
    "\n",
    "# 其他\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     广东省\n",
       "3      北京\n",
       "6     上海市\n",
       "9     浙江省\n",
       "12    江苏省\n",
       "Name: 地区, dtype: object"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region = df_居民人均可支配收入累计值['地区']\n",
    "region"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['2022年第一季度', '2021年第四季度', '2021年第三季度', '2021年第二季度', '2021年第一季度']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 四个季度\n",
    "group = [df.columns.tolist()[1],df.columns.tolist()[2],df.columns.tolist()[3],df.columns.tolist()[4],df.columns.tolist()[5]]\n",
    "group"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('广东省', '2022年第一季度'),\n",
       " ('广东省', '2021年第四季度'),\n",
       " ('广东省', '2021年第三季度'),\n",
       " ('广东省', '2021年第二季度'),\n",
       " ('广东省', '2021年第一季度'),\n",
       " ('北京', '2022年第一季度'),\n",
       " ('北京', '2021年第四季度'),\n",
       " ('北京', '2021年第三季度'),\n",
       " ('北京', '2021年第二季度'),\n",
       " ('北京', '2021年第一季度'),\n",
       " ('上海市', '2022年第一季度'),\n",
       " ('上海市', '2021年第四季度'),\n",
       " ('上海市', '2021年第三季度'),\n",
       " ('上海市', '2021年第二季度'),\n",
       " ('上海市', '2021年第一季度'),\n",
       " ('浙江省', '2022年第一季度'),\n",
       " ('浙江省', '2021年第四季度'),\n",
       " ('浙江省', '2021年第三季度'),\n",
       " ('浙江省', '2021年第二季度'),\n",
       " ('浙江省', '2021年第一季度'),\n",
       " ('江苏省', '2022年第一季度'),\n",
       " ('江苏省', '2021年第四季度'),\n",
       " ('江苏省', '2021年第三季度'),\n",
       " ('江苏省', '2021年第二季度'),\n",
       " ('江苏省', '2021年第一季度')]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 准备x轴坐标数据\n",
    "x = [ (diqu, categroy) for diqu in region for categroy in group ]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13360, 44993, 35694, 23604, 12636, 16230, 54854, 43592, 28897, 15472, 6639, 22306, 17619, 11490, 6225, 20630, 75002, 56498, 38138, 19585, 22274, 81518, 61243, 41381, 21189, 10016, 33303, 26125, 17383, 9326, 22663, 78027, 58907, 40357, 21548, 23772, 82429, 61915, 42348, 22636, 12891, 38521, 31985, 22535, 12006, 19366, 57541, 44712, 30998, 18263, 22784, 68487, 52758, 36294, 21600, 12541, 35247, 28474, 20357, 11686, 16490, 47498, 36227, 25119, 15500, 19251, 57743, 44267, 30491, 18194, 10952, 26791, 20267, 14455, 10215)\n"
     ]
    }
   ],
   "source": [
    "# 准备y轴坐标数据\n",
    "y = sum(zip(df['2022年第一季度'], df['2021年第四季度'], df['2021年第三季度'], df['2021年第二季度'], df['2021年第一季度']), ())\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('jidu_counts', 75), ('region', 5), ('x_axis', 25), ('y_counts', 75)\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"31ffc885-5c6c-4e25-8fa7-44268f2d29fa\" data-root-id=\"3862\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"2130ab3b-77c6-466e-9c8c-29e8444b037d\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3872\"}],\"center\":[{\"id\":\"3874\"},{\"id\":\"3878\"},{\"id\":\"3914\"}],\"left\":[{\"id\":\"3875\"}],\"outline_line_color\":null,\"plot_height\":300,\"plot_width\":2000,\"renderers\":[{\"id\":\"3904\"},{\"id\":\"3919\"},{\"id\":\"3933\"}],\"title\":{\"id\":\"3863\"},\"toolbar\":{\"id\":\"3887\"},\"x_range\":{\"id\":\"3861\"},\"x_scale\":{\"id\":\"3868\"},\"y_range\":{\"id\":\"3866\"},\"y_scale\":{\"id\":\"3870\"}},\"id\":\"3862\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fields\":[\"2015\"]},\"id\":\"3896\",\"type\":\"Stack\"},{\"attributes\":{\"overlay\":{\"id\":\"3885\"}},\"id\":\"3881\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\\u5806\\u53e0\\u67f1\\u72b6\\u56fe\"},\"id\":\"3863\",\"type\":\"Title\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3879\"},{\"id\":\"3880\"},{\"id\":\"3881\"},{\"id\":\"3882\"},{\"id\":\"3883\"},{\"id\":\"3884\"},{\"id\":\"3886\"}]},\"id\":\"3887\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"3875\"},\"dimension\":1,\"ticker\":null},\"id\":\"3878\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"jidu_counts\":[13360,44993,35694,23604,12636,16230,54854,43592,28897,15472,6639,22306,17619,11490,6225,20630,75002,56498,38138,19585,22274,81518,61243,41381,21189,10016,33303,26125,17383,9326,22663,78027,58907,40357,21548,23772,82429,61915,42348,22636,12891,38521,31985,22535,12006,19366,57541,44712,30998,18263,22784,68487,52758,36294,21600,12541,35247,28474,20357,11686,16490,47498,36227,25119,15500,19251,57743,44267,30491,18194,10952,26791,20267,14455,10215],\"region\":[\"\\u5e7f\\u4e1c\\u7701\",\"\\u5317\\u4eac\",\"\\u4e0a\\u6d77\\u5e02\",\"\\u6d59\\u6c5f\\u7701\",\"\\u6c5f\\u82cf\\u7701\"],\"x_axis\":[[\"\\u5e7f\\u4e1c\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"]],\"y_counts\":[13360,44993,35694,23604,12636,16230,54854,43592,28897,15472,6639,22306,17619,11490,6225,20630,75002,56498,38138,19585,22274,81518,61243,41381,21189,10016,33303,26125,17383,9326,22663,78027,58907,40357,21548,23772,82429,61915,42348,22636,12891,38521,31985,22535,12006,19366,57541,44712,30998,18263,22784,68487,52758,36294,21600,12541,35247,28474,20357,11686,16490,47498,36227,25119,15500,19251,57743,44267,30491,18194,10952,26791,20267,14455,10215]},\"selected\":{\"id\":\"3911\"},\"selection_policy\":{\"id\":\"3912\"}},\"id\":\"3860\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3895\"}},\"fill_color\":{\"value\":\"#99d594\"},\"line_color\":{\"value\":\"#99d594\"},\"top\":{\"expr\":{\"id\":\"3896\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3902\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"value\":\"2017\"},\"renderers\":[{\"id\":\"3933\"}]},\"id\":\"3943\",\"type\":\"LegendItem\"},{\"attributes\":{\"formatter\":{\"id\":\"3907\"},\"minor_tick_line_color\":null,\"ticker\":{\"id\":\"3873\"}},\"id\":\"3872\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"3860\"},\"glyph\":{\"id\":\"3902\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2015\",\"nonselection_glyph\":{\"id\":\"3903\"},\"selection_glyph\":null,\"view\":{\"id\":\"3905\"}},\"id\":\"3904\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3885\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"3873\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fields\":[\"2015\"]},\"id\":\"3897\",\"type\":\"Stack\"},{\"attributes\":{\"items\":[{\"id\":\"3915\"},{\"id\":\"3929\"},{\"id\":\"3943\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"3914\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"3876\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3899\"}},\"fill_color\":{\"value\":\"#fc8d59\"},\"line_color\":{\"value\":\"#fc8d59\"},\"top\":{\"expr\":{\"id\":\"3900\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3931\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3911\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3912\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"3860\"}},\"id\":\"3905\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"2015\"},\"renderers\":[{\"id\":\"3904\"}]},\"id\":\"3915\",\"type\":\"LegendItem\"},{\"attributes\":{\"fields\":[]},\"id\":\"3895\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\"]},\"id\":\"3899\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3897\"}},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"3898\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3917\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3870\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3897\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#ffffbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#ffffbf\"},\"top\":{\"expr\":{\"id\":\"3898\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3918\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"3860\"},\"glyph\":{\"id\":\"3917\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2016\",\"nonselection_glyph\":{\"id\":\"3918\"},\"selection_glyph\":null,\"view\":{\"id\":\"3920\"}},\"id\":\"3919\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"end\":16,\"start\":0},\"id\":\"3866\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"3880\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3882\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"3883\",\"type\":\"ResetTool\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3899\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#fc8d59\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#fc8d59\"},\"top\":{\"expr\":{\"id\":\"3900\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3932\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3884\",\"type\":\"HelpTool\"},{\"attributes\":{\"formatter\":{\"id\":\"3909\"},\"minor_tick_line_color\":null,\"ticker\":{\"id\":\"3876\"}},\"id\":\"3875\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3879\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"3860\"},\"glyph\":{\"id\":\"3931\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"2017\",\"nonselection_glyph\":{\"id\":\"3932\"},\"selection_glyph\":null,\"view\":{\"id\":\"3934\"}},\"id\":\"3933\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"factors\":[[\"\\u5e7f\\u4e1c\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u5e7f\\u4e1c\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u5317\\u4eac\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u4e0a\\u6d77\\u5e02\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u6d59\\u6c5f\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2022\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u56db\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e09\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e8c\\u5b63\\u5ea6\"],[\"\\u6c5f\\u82cf\\u7701\",\"2021\\u5e74\\u7b2c\\u4e00\\u5b63\\u5ea6\"]],\"range_padding\":0.1},\"id\":\"3861\",\"type\":\"FactorRange\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\",\"2017\"]},\"id\":\"3900\",\"type\":\"Stack\"},{\"attributes\":{\"source\":{\"id\":\"3860\"}},\"id\":\"3920\",\"type\":\"CDSView\"},{\"attributes\":{\"source\":{\"id\":\"3860\"}},\"id\":\"3934\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3895\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#99d594\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#99d594\"},\"top\":{\"expr\":{\"id\":\"3896\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x_axis\"}},\"id\":\"3903\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3907\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"2016\"},\"renderers\":[{\"id\":\"3919\"}]},\"id\":\"3929\",\"type\":\"LegendItem\"},{\"attributes\":{\"axis\":{\"id\":\"3872\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3874\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3909\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fields\":[\"2015\",\"2016\"]},\"id\":\"3898\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"3868\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"$name\",\"@fruits: @$name\"],[\"counts\",\"@y_counts\"],[\"detail\",\"@x_axis\"]]},\"id\":\"3886\",\"type\":\"HoverTool\"}],\"root_ids\":[\"3862\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"2130ab3b-77c6-466e-9c8c-29e8444b037d\",\"root_ids\":[\"3862\"],\"roots\":{\"3862\":\"31ffc885-5c6c-4e25-8fa7-44268f2d29fa\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3862"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "from bokeh.transform import factor_cmap\n",
    "# 颜色的准备\n",
    "colors=Spectral3\n",
    "\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        region = df_居民人均可支配收入累计值['地区'],\n",
    "        jidu_counts = y,\n",
    "        x_axis = x,\n",
    "        y_counts = y,     \n",
    "    )\n",
    ")\n",
    "# 点击的交互式数据\n",
    "TOOLTIPS = [\n",
    "    # ('标题','数据')\n",
    "#     (\"$name\", \"@fruits: @$name\"),\n",
    "    (\"counts\",\"@y_counts\"),\n",
    "    (\"detail\",\"@x_axis\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=FactorRange(*x),\n",
    "    plot_width=2000, \n",
    "    plot_height=300,\n",
    "    title=\"堆叠柱状图\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘图(vbar_stack),直接堆叠各年数据\n",
    "p.vbar_stack(years,\n",
    "             x='x_axis',\n",
    "#              top=\"y_counts\",\n",
    "             width=0.9,\n",
    "             color=colors,\n",
    "             source=source,\n",
    "             legend=[value(x) for x in years]\n",
    ") # legend=[{'value': '2015'}, {'value': '2016'}, {'value': '2017'}]\n",
    "    \n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.y_range.end = 16\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.axis.minor_tick_line_color = None\n",
    "p.outline_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "183.449px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
